package graphicView;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;

import model.*;
import java.util.Observable;

//ClassGraphicObject is built with ClassImpl object. Run ClassGraphicObject.drawClass(g) where g is the graphics object of the JPanel.
/**
 * Team EBE
 * 
 * ClassGraphicObject.java is the incomplete implementation of a graphical
 * object representing the class
 * 
 */
public class ClassGraphicObject extends Observable {
	private ClassImpl classObject;
	private boolean active = false;

	public ClassGraphicObject(ClassImpl classObjectIn) {
		this.classObject = classObjectIn;
	}
	
	public ClassImpl getModel(){
		return classObject;
	}

	public void activate() {
		active = true;
	}

	public void deactivate() {
		active = false;
	}

	public boolean isActive() {
		return active;
	}

	public int getHeight() {
		return classObject.getHeight();
	}

	public int getWidth() {
		return classObject.getWidth();
	}

	public void setHeight(int height) {
		classObject.setHeight(height);
	}

	public void setWidth(int width) {
		classObject.setWidth(width);
	}

	public int getoX() {
		return classObject.getoX();
	}

	public void setoX(int oX) {
		classObject.setoX(oX);
	}

	public int getoY() {
		return classObject.getoY();
	}

	public void setoY(int oY) {
		classObject.setoY(oY);
	}

	public void sendToInspector() {
		System.out.println("bleck");
		setChanged();
		notifyObservers(this.classObject);
	}

	public void drawClass(Graphics g, Boolean relationshipActive) {
		classObject.updateSize();
		System.out.println("sad;lfkj");
		Font title = new Font("serif", Font.PLAIN, 20);
		Font attr = new Font("serif", Font.PLAIN, 12);
		int oX = classObject.getoX();
		String debug = "origin: (" + classObject.getoX() + ","
				+ classObject.getoY() + ")";
		System.out.println(debug);
		g.setColor(Color.white);
		g.fillRect(oX, classObject.getoY(), classObject.getWidth(),classObject.getHeight());
		g.setColor(Color.lightGray);
		g.fillRect(oX, classObject.getoY(), classObject.getWidth(), 20);

		g.setColor(Color.black);
		g.drawRect(oX, classObject.getoY(), classObject.getWidth(),
				classObject.getHeight());

		g.setFont(title);
		int ydisp = classObject.getoY() + 15;

		g.drawString(classObject.getName(), oX + 5, ydisp);

		// y displacement starts from oY + the size of the title box, we should
		// make this deterministic later

		g.setFont(attr);
		
		for (AttributeImpl a : classObject.getAttributes()) {
			ydisp += 17;
			g.drawString(a.toString(), oX + 5, ydisp);
		}
		ydisp += 5;
		g.drawLine(oX, ydisp, oX + 200, ydisp);
		//ydisp -= 5;
		for (OperationImpl o : classObject.getOperations()) {
			ydisp += 17;
			g.drawString(o.toString(), oX + 5, ydisp);
		}
		if(relationshipActive){
		for (AnchorPoint ap : classObject.getAnchorPoints()){
			g.setColor(Color.PINK);
			g.fillOval(ap.x - 5, ap.y - 5, 10, 10);
		}
		g.setColor(Color.BLACK);
		}

	}

}
